<template>
  <loading-state :message="$t('CONFIRM_EMAIL')" />
</template>
<script>
import LoadingState from '../../components/widgets/LoadingState'
import Auth from '../../api/auth'
import { DEFAULT_REDIRECT_URL } from '../../constants'
export default {
  components: {
    LoadingState,
  },
  props: {
    tenantId: {
      type: String,
      default: '',
    },
    userId: {
      type: String,
      default: '',
    },
    confirmationToken: {
      type: String,
      default: '',
    },
  },
  mounted () {
    this.confirmToken()
  },
  methods: {
    async confirmToken () {
      try {
        await Auth.verifyPasswordToken({
          confirmationToken: this.confirmationToken,
          tenantId: this.tenantId,
          userId: this.userId
        })
        window.location = DEFAULT_REDIRECT_URL
      } catch (error) {
        window.location = DEFAULT_REDIRECT_URL
      }
    },
  },
}
</script>
